package com.example.shopuser.controller;

import com.example.shopcommon.dao.entity.User;
import com.example.shopuser.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/get")
    public User get(@RequestParam("id") Long id){
        return userService.get(id);
    }

    @PostMapping("/reduce")
    public String reduce(@RequestBody User user){
        try {
            userService.reduct(user);
        }catch (Exception e){
            e.printStackTrace();
            return "FAIL";
        }
        return "SUCCESS";
    }
}
